package org.yoyo.classroom.service;

//package org.yoyo.classroom.service;

import org.springframework.stereotype.Service;
import org.yoyo.classroom.domain.po.Post;
import org.yoyo.classroom.mapper.PostMapper;

import java.util.List;

@Service
public class PostService {

    private final PostMapper postMapper;

    public PostService(PostMapper postMapper) {
        this.postMapper = postMapper;
    }

    public List<Post> getPosts(int page, int size) {
        int offset = (page - 1) * size;
        return postMapper.findPosts(offset, size);
    }

    public void createPost(Post post) {
        postMapper.insertPost(post);
    }

    public Post getPostById(int id) {
        return postMapper.findPostById(id);
    }
}
